<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="地热井名称" prop="wellname">
        <el-input v-model="queryParams.wellname" placeholder="请输入地热井名称" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="地热井类型" prop="welltype">
        <el-select v-model="queryParams.welltype" placeholder="请选择地热井类型" clearable size="small">
          <el-option v-for="dict in dict.type.geothermaltype" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="利用方式" prop="utilizationmode">
        <el-select v-model="queryParams.utilizationmode" placeholder="请选择利用方式" clearable size="small">
          <el-option v-for="dict in dict.type.utilizationmode" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="使用状态" prop="enabled">
        <el-select v-model="queryParams.enabled" placeholder="请选择使用状态" clearable size="small">
          <el-option v-for="dict in dict.type.enabled" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!--  <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['well:geothermalwellinfo:add']">新增</el-button> -->
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['well:geothermalwellinfo:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <!--  <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['well:geothermalwellinfo:edit']">修改</el-button> -->
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['well:geothermalwellinfo:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <!-- <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['well:geothermalwellinfo:remove']">删除</el-button> -->
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['well:geothermalwellinfo:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <importData :authority="importData_authority" :api="importData_api" :title="importData_title" :templateName="importData_templateName"></importData>
      </el-col>
      <el-col :span="1.5">
        <!--  <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['well:geothermalwellinfo:export']">导出</el-button> -->
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['well:geothermalwellinfo:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="geothermalwellinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="wellno" />
      <!--   <el-table-column label="隶属项目编号" align="center" prop="projectno" /> -->
      <el-table-column label="地热井名称" align="center" prop="wellname" width="300">
        <template slot-scope="scope">
          <span>{{ scope.row.wellname.split("#")[0] }}</span>
        </template>
      </el-table-column>
      <!--  <el-table-column label="经度坐标" align="center" prop="longitude" />
      <el-table-column label="纬度坐标" align="center" prop="latitude" /> -->
      <el-table-column label="孔口高程" align="center" prop="atitude" />
      <el-table-column label="孔口直径" align="center" prop="orificediameter" />
      <el-table-column label="管口直径" align="center" prop="nozzlediameter" />
      <el-table-column label="管壁厚度" align="center" prop="pipewalldiameter" />
      <el-table-column label="地热井类型" align="center" prop="welltype" width="100px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.geothermaltype" :value="scope.row.welltype" />
        </template>
      </el-table-column>
      <el-table-column label="井深" align="center" prop="welldepth" />
      <el-table-column label="报警水位" align="center" prop="waringlevel" />
      <el-table-column label="静止水位" align="center" prop="staticlevel" />
      <el-table-column label="静水位埋深" align="center" prop="staticdepth" width="90px" />
      <el-table-column label="动水位埋深" align="center" prop="dynamicdepth" width="90px" />
      <el-table-column label="利用方式" align="center" prop="utilizationmode" width="110">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.utilizationmode" :value="scope.row.utilizationmode" />
        </template>
      </el-table-column>
      <el-table-column label="成井温度" align="center" prop="temperature" />
      <el-table-column label="成井流量" align="center" prop="wellflow" />
      <el-table-column label="起始取水位" align="center" prop="startlevel" width="90px" />
      <el-table-column label="终止取水位" align="center" prop="endlevel" width="90px" />
      <el-table-column label="使用状态" align="center" prop="enabled">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.enabled" :value="scope.row.enabled" />
        </template>
      </el-table-column>
      <!--  <el-table-column label="热力井概况" align="center" prop="content" /> -->
      <el-table-column label="创建日期" align="center" prop="createtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!--   <el-table-column label="更新日期" align="center" prop="updatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="190px">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['well:geothermalwellinfo:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['well:geothermalwellinfo:remove']">删除</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['well:geothermalwellinfo:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['well:geothermalwellinfo:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改地热井基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body custom-class="welldialog">
      <template slot="title">
        <div>
          <i class="el-icon-edit"></i>
          <span> {{title}}</span>
        </div>
      </template>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <table class="table">
          <caption style="font-size:20px;padding:10px 0px">地热井基本信息</caption>
          <tr>
            <th class="leibie" colspan="2">项目名称</th>
            <th>
              <el-select v-model="projectEntryname" filterable placeholder="请搜索隶属项目" @change="projectEntrynameChange">
                <el-option v-for="item in projectOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <!--  <el-input v-model="queryParams.entryname" placeholder="请输入项目名称" /> -->
            </th>
            <th class="leibie" rowspan="4">地热井</th>
            <th class="leibie2">井深</th>
            <th>
              <el-input v-model="form.welldepth" placeholder="请输入井深" />
            </th>
          </tr>
          <tr>
            <th class="leibie" colspan="2">项目编号</th>
            <th>
              <el-input v-model="form.projectno" placeholder="请输入隶属项目编号" />
            </th>
            <th class="leibie2">静水位</th>
            <th>
              <el-input v-model="form.staticlevel" placeholder="请输入静止水位" />
            </th>
          </tr>
          <tr>
            <th class="leibie" colspan="2">地热井名称</th>
            <th>
              <el-input v-model="form.wellname" placeholder="请输入地热井名称" />
            </th>
            <th class="leibie2">成井温度</th>
            <th>
              <el-input v-model="form.temperature" placeholder="请输入成井温度" />
            </th>
          </tr>
          <tr>
            <th class="leibie" rowspan="2">坐标</th>
            <th class="leibie2">经度</th>
            <th>
              <el-input v-model="form.longitude" placeholder="请输入经度坐标" />
            </th>
            <th class="leibie2">成井流量</th>
            <el-input v-model="form.wellflow" placeholder="请输入成井流量" />
          </tr>
          <tr>
            <th>纬度</th>
            <th>
              <el-input v-model="form.latitude" placeholder="请输入纬度坐标" />
            </th>
            <th class="leibie" rowspan="5">水位</th>
            <th>静水位埋深</th>
            <th>
              <el-input v-model="form.staticdepth" placeholder="请输入静水位埋深" />
            </th>
          </tr>
          <tr>
            <th class="leibie" rowspan="4">钻孔信息</th>
            <th>孔口高度</th>
            <th>
              <el-input v-model="form.atitude" placeholder="请输入孔口高程" />
            </th>
            <th>动水位埋深</th>
            <th>
              <el-input v-model="form.dynamicdepth" placeholder="请输入动水位埋深" />
            </th>
          </tr>
          <tr>
            <th>孔口直径</th>
            <th>
              <el-input v-model="form.orificediameter" placeholder="请输入孔口直径" />
            </th>
            <th>起始取水位</th>
            <th>
              <el-input v-model="form.startlevel" placeholder="请输入起始取水位" />
            </th>
          </tr>
          <tr>
            <th>管口直径</th>
            <th>
              <el-input v-model="form.nozzlediameter" placeholder="请输入管口直径" />
            </th>
            <th>终止取水位</th>
            <th>
              <el-input v-model="form.endlevel" placeholder="请输入终止取水位" />
            </th>
          </tr>
          <tr>
            <th>管壁厚度</th>
            <th>
              <el-input v-model="form.pipewalldiameter" placeholder="请输入管壁厚度" />
            </th>
            <th>报警水位</th>
            <th>
              <el-input v-model="form.waringlevel" placeholder="请输入报警水位" />
            </th>
          </tr>
          <tr>
            <th class="leibie" colspan="2">使用状态</th>
            <th>
              <el-select v-model="form.enabled" placeholder="请选择使用状态">
                <el-option v-for="dict in dict.type.enabled" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
              </el-select>
            </th>
            <th class="leibie" colspan="2">录入人</th>
            <th>
              <el-input v-model="form.inputuser" placeholder="请输入录入人" />
            </th>
          </tr>
          <tr>
            <th class="xmgk" colspan="2">地热井概况</th>
            <th colspan="4">
              <el-input v-model="form.content" autosize type="textarea"></el-input>
            </th>
          </tr>

        </table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGeothermalwellinfo, getGeothermalwellinfo, delGeothermalwellinfo, addGeothermalwellinfo, updateGeothermalwellinfo } from "@/api/geoInfor/geothermalwellinfo";
import { listProjectinfo, getProjectinfo, delProjectinfo, addProjectinfo, updateProjectinfo } from "@/api/geoInfor/projectinfo";
import ImportData from "@/components/ImportData";
export default {
  name: "Geothermalwellinfo",
  components: { ImportData },
  dicts: ['geothermaltype', 'utilizationmode', 'enabled'],
  data() {
    return {
      importData_authority: "well:geothermalwellinfo:import",
      importData_api: "well/geothermalwellinfo/",
      importData_title: "导入地热井基本信息数据",
      importData_templateName: "地热井基本信息数据模板",
      projectEntryname: '',
      projectOptions: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 地热井基本信息表格数据
      geothermalwellinfoList: [],
      //项目基本信息表格数据
      projectinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 地热井查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wellname: null,
        welltype: null,
        utilizationmode: null,
        enabled: null,
        entryname: null,
      },
      // 项目查询参数
      projectQueryParams: {
        /*  pageNum: 1,
         pageSize: 9, */
        entryname: null,
        addcode: null,
        geothermaltype: null,
        utilizationmode: null,
        enabled: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  watch: {

  },
  created() {
    this.getList();
    this.getProjectList();
  },
  methods: {
    projectEntrynameChange(select) {
      console.log(this.projectEntryname)
      console.log(select)
      this.form.projectno = select;
    },
    projectno2name(projectno) {
      console.log(projectno)
      return this.projectinfoList.filter((item) => {
        return item.projectno == projectno;
      })
    },
    /** 查询项目基本信息选择*/
    getProjectOptions(projectinfoList) {
      this.projectOptions = projectinfoList.map((item) => {
        return {
          value: item.projectno,
          label: item.entryname
        }
      });
    },
    /** 查询项目基本信息列表 */
    getProjectList() {
      this.loading = true;
      listProjectinfo(this.projectQueryParams).then(response => {
        this.projectinfoList = response.rows;
        this.getProjectOptions(this.projectinfoList);
        this.loading = false;
      });
    },
    /** 查询地热井基本信息列表 */
    getList() {
      this.loading = true;
      listGeothermalwellinfo(this.queryParams).then(response => {
        this.geothermalwellinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.projectEntryname = null;
      this.form = {
        wellno: null,
        projectno: null,
        wellname: null,
        longitude: null,
        latitude: null,
        atitude: null,
        orificediameter: null,
        nozzlediameter: null,
        pipewalldiameter: null,
        welltype: null,
        welldepth: null,
        waringlevel: null,
        staticlevel: null,
        staticdepth: null,
        dynamicdepth: null,
        utilizationmode: null,
        temperature: null,
        wellflow: null,
        startlevel: null,
        endlevel: null,
        enabled: null,
        content: null,
        createtime: null,
        updatetime: null,
        inputuser: null,
        entryname: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.wellno)
      this.single = selection.length !== 1
      this.multiple = !selection.length

    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加地热井基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const wellno = row.wellno || this.ids
      getGeothermalwellinfo(wellno).then(response => {
        this.form = response.data;
        /**设置选择名称 */
        this.projectEntryname = this.form.projectno;
        this.open = true;
        this.title = "修改地热井基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.wellno != null) {
            updateGeothermalwellinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGeothermalwellinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const wellnos = row.wellno || this.ids;
      this.$modal.confirm('是否确认删除地热井基本信息编号为"' + wellnos + '"的数据项？').then(function () {
        return delGeothermalwellinfo(wellnos);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      if (this.ids.length > 0) {
        this.download('well/geothermalwellinfo/export', {
          ...this.queryParams,
          "wellnos": this.ids.toString()
        }, `geothermalwellinfo_${new Date().getTime()}.xlsx`)
        return;
      }
      this.download('well/geothermalwellinfo/export', {
        ...this.queryParams
      }, `geothermalwellinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
.wellDialog {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  .el-dialog__header {
    padding-top: 10px;
    font-size: 18px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    background-color: #ebebeb;
    border-bottom: 1px solid rgb(185, 181, 181) !important;
  }
}
.el-table {
  cursor: pointer;
  ::-webkit-scrollbar {
    width: 6px;
    height: 10px;
  }
  ::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.9);
    border-radius: 10px;
  }
  ::-webkit-scrollbar-thumb {
    border-radius: 5px;
    background: rgba(66, 66, 66, 0.5);
    -webkit-box-shadow: inset 0 0 6px rgba(227, 227, 227, 87.5);
  }
  ::-webkit-scrollbar-thumb:window-inactive {
    background: rgba(227, 227, 227, 0.5);
  }
}
.table,
th,
tr {
  border: 1px solid black;
  border-collapse: collapse;
  text-align: center;
}
.xmgk {
  height: 100px;
  background-color: rgb(193, 194, 255, 0.6);
}
.leibie {
  width: 100px;
  background-color: rgb(193, 194, 255, 0.6);
}
.leibie2 {
  width: 100px;
}
</style>
<style lang="scss">
.welldialog {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  .el-dialog__header {
    padding-top: 10px;
    font-size: 18px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    background-color: #ebebeb;
    border-bottom: 1px solid rgb(185, 181, 181) !important;
  }
  .el-dialog__body {
    padding: 5px 40px !important;
  }
}
</style>